﻿module Program
open Gauss
open System
open System.IO
open MathNet.Numerics
open MathNet.Numerics.FSharp
open MathNet.Numerics.LinearAlgebra.Double
open System.Collections.Generic

//lettura dei dati da file

let stream = File.Open("..\..\data\iris.data",FileMode.Open, FileAccess.Read)
let stream_reader = new StreamReader(stream) 
let text = stream_reader.ReadToEnd()
stream_reader.Close()
stream.Close()


let labels = Map.ofList([("Iris-setosa",0.); ("Iris-versicolor",1.); ("Iris-virginica",2.)])

let input =
    let splitted_text = text.Split(',','\n')  |> Seq.filter(fun elem -> elem <> "") |> Seq.toList
    let rec build_vectors list =
      match list with
      [] -> []
      |(x1::x2::x3::x4::x5 :: xs) -> 
        let point = new DenseVector([|float x1; float x2; float x3; float x4|])
        let label = labels.[x5]
        GaussianPoint(point, label) :: build_vectors xs
    

    List(build_vectors splitted_text |> Seq.ofList)

//function test
let res = List(compute_gausssian input (List([0.;1.;2.])))

//print dei risultati
for y in [0..2] do
  Console.WriteLine(sprintf "Classifing class %d : " y)
  let res =
    res |> Seq.filter(fun (p,y1,y2) -> y1 = float y) 
        |> Seq.filter(fun (p,y1,y2) -> y1 <> y2) 
        |> Seq.length
  Console.WriteLine(sprintf "Errors = %d" res)



  Console.Read()